﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using LibraryO2S;

public partial class Administrator_StatisticEvent : System.Web.UI.Page
{
    Dataprocess data = new Dataprocess();
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {

            txtdate.Text = DateTime.Now.Day.ToString("00") + "/" + DateTime.Now.Month.ToString("00") + "/" + DateTime.Now.Year.ToString("0000");
            txtdate1.Text = DateTime.Now.Day.ToString("00") + "/" + DateTime.Now.Month.ToString("00") + "/" + DateTime.Now.Year.ToString("0000");

            LoadDrop();

            ddlloaithe.Items.FindByValue("").Selected = true;
            ddlnv.Items.FindByValue("").Selected = true;

            //CollectionPager1.DataSource = LoadData().DefaultView;
            //CollectionPager1.PageSize = 50;
            //CollectionPager1.BindToControl = rptData;
            //rptData.DataSource = CollectionPager1.DataSourcePaged;
            //rptData.DataBind();

        }
    }
    public void LoadDrop()
    {
        

        ddlloaithe.DataSource = data.allSystem("select * from tblCardType");
        ddlloaithe.DataTextField = "Name";
        ddlloaithe.DataValueField = "Code";
        ddlloaithe.DataBind();

        ddlnv.DataSource = data.allSystem("select * from tblUser");
        ddlnv.DataTextField = "FullName";
        ddlnv.DataValueField = "Code";
        ddlnv.DataBind();


        ddlloaithe.Items.Add("");
        ddlnv.Items.Add("");

    }
    public DataTable LoadData(string date, string date1, string cardtype, string usercode)
    {
        DataTable table = new DataTable();
        DataColumn dtColumn = new DataColumn("date");
        table.Columns.Add(dtColumn);
        DataColumn dtColumn1 = new DataColumn("mathe");
        table.Columns.Add(dtColumn1);
        DataColumn dtColumn2 = new DataColumn("makh");
        table.Columns.Add(dtColumn2);
        DataColumn dtColumn3 = new DataColumn("tenkh");
        table.Columns.Add(dtColumn3);
        DataColumn dtColumn4 = new DataColumn("loaithe");
        table.Columns.Add(dtColumn4);
        DataColumn dtColumn5 = new DataColumn("anh");
        table.Columns.Add(dtColumn5);
        DataColumn dtColumn6 = new DataColumn("Id");
        table.Columns.Add(dtColumn6);


        DataTable db = data.allSystem(" select dbo.tblEventSwim.Id,dbo.tblEventSwim.Date as [Ngay], dbo.tblEventSwim.CardNumber as [mathe], dbo.tblCard.Code as [makh], dbo.tblCard.AccountName as [ten], dbo.tblCardType.Name as [loaithe], dbo.tblEventSwim.PicDir as [anh] from tblEventSwim LEFT JOIN tblCard ON dbo.tblEventSwim.CardNumber=dbo.tblCard.CardNumber LEFT JOIN tblCardType ON dbo.tblCard.CardTypeCode=tblCardType.Code where dbo.tblEventSwim.Date>='" + date + "' and dbo.tblEventSwim.Date<='" + date1 + "' and tblCardType.Code  like '%" + cardtype + "%' and  tblEventSwim.UserCode like '%" + usercode + "%' order by  dbo.tblEventSwim.Date desc  ");
        foreach (DataRow dr in db.Rows)
        {

            DataRow dtRow = table.NewRow();
            dtRow[0] = dr["Ngay"].ToString();
            dtRow[1] = dr["mathe"].ToString();
            dtRow[2] = dr["makh"].ToString();
            dtRow[3] = dr["ten"].ToString();
            dtRow[4] = dr["loaithe"].ToString();
            dtRow[5] = dr["anh"].ToString();
            dtRow[6] = dr["Id"].ToString();
            table.Rows.Add(dtRow);

        }

        return table;
    }

    public DataTable LoadData()
    {
        DataTable table = new DataTable();
        DataColumn dtColumn = new DataColumn("date");
        table.Columns.Add(dtColumn);
        DataColumn dtColumn1 = new DataColumn("mathe");
        table.Columns.Add(dtColumn1);
        DataColumn dtColumn2 = new DataColumn("makh");
        table.Columns.Add(dtColumn2);
        DataColumn dtColumn3 = new DataColumn("tenkh");
        table.Columns.Add(dtColumn3);
        DataColumn dtColumn4 = new DataColumn("loaithe");
        table.Columns.Add(dtColumn4);
        DataColumn dtColumn5 = new DataColumn("anh");
        table.Columns.Add(dtColumn5);
        DataColumn dtColumn6 = new DataColumn("Id");
        table.Columns.Add(dtColumn6);


        DataTable db = data.allSystem(" select top 200 dbo.tblEventSwim.Id,dbo.tblEventSwim.Date as [Ngay], dbo.tblEventSwim.CardNumber as [mathe], dbo.tblCard.Code as [makh], dbo.tblCard.AccountName as [ten], dbo.tblCardType.Name as [loaithe], dbo.tblEventSwim.PicDir as [anh] from tblEventSwim LEFT JOIN tblCard ON dbo.tblEventSwim.CardNumber=dbo.tblCard.CardNumber LEFT JOIN tblCardType ON dbo.tblCard.CardTypeCode=tblCardType.Code  order by  dbo.tblEventSwim.Date desc  ");
        foreach (DataRow dr in db.Rows)
        {

            DataRow dtRow = table.NewRow();
            dtRow[0] = dr["Ngay"].ToString();
            dtRow[1] = dr["mathe"].ToString();
            dtRow[2] = dr["makh"].ToString();
            dtRow[3] = dr["ten"].ToString();
            dtRow[4] = dr["loaithe"].ToString();
            dtRow[5] = dr["anh"].ToString();
            dtRow[6] = dr["Id"].ToString();
            table.Rows.Add(dtRow);

        }

        return table;
    }

    protected void btnAdnew1_Click(object sender, EventArgs e)
    {
        Response.Redirect("BannerAdd.aspx");
    }
    protected void btnDelete_Click(object sender, EventArgs e)
    {

    }
    protected void btnUpdateDisplayOrder_Click(object sender, EventArgs e)
    {

    }
    protected void btnthongke_Click(object sender, EventArgs e)
    {
        string date = txtdate.Text.Substring(3, 2) + "/" + txtdate.Text.Substring(0, 2) + "/" + txtdate.Text.Substring(6, 4) + " 00:00";
        string date1 = txtdate1.Text.Substring(3, 2) + "/" + txtdate1.Text.Substring(0, 2) + "/" + txtdate1.Text.Substring(6, 4) + " 23:59";
        string cardtype = ddlloaithe.SelectedValue;
        string usercode = ddlnv.SelectedValue;


        CollectionPager1.DataSource = LoadData(date, date1, cardtype, usercode).DefaultView;
        CollectionPager1.PageSize = 2000;
        CollectionPager1.BindToControl = rptData;
        rptData.DataSource = CollectionPager1.DataSourcePaged;
        rptData.DataBind();



    }
}